<template>
  <div id="header">
    <div class="header">
      <div class="header-left">
        <a href="/" v-if="!isFixed">
          <img class="logo" :src="$store.state.setting.LOGO" alt="">
        </a>
        <div
          v-if="isFixed"
          class="bar-menu-wrap"
        >
          <div class="bar-menu primary">
            <img class="bar-img" src="/img/home/classify_icon.png" alt="">
            <span class="bar-title">海量模板，每天更新</span>
          </div>
          <div class="bar-menu-list" >
              <TemplateClass :barList="barList"></TemplateClass>
          </div>
        </div>
        <ul>
          <a href="/">
            <li :class="{'menu-list primary-hover': true, primary: path == '/'}">首页</li>
          </a>
          <a href="/templateList">
            <li :class="{'menu-list primary-hover': true, primary: path.indexOf('/templateList') > -1}">在线设计</li>
          </a>
          <a href="/print">
            <li :class="{'menu-list primary-hover': true, primary: path.indexOf('/print') > -1}">在线印刷</li>
          </a>
        </ul>
      </div>
      <div class="header-right">
        <div class="search-input">
          <div class="input-select">
            <input
              v-model="keywords"
              placeholder="请输入模板关键字"
              @focus="isShowSearchBox(true)"
              @blur="isShowSearchBox(false)"
              class="primary-border"
              @keydown.enter="handleSearch(keywords)"
            >
            <span class="search-btn primary" @click="handleSearch(keywords)">搜索</span>
          </div>
          <div v-if="show" class="hot-search">
            <p>
              <span>热门搜索：</span>
              <span class="search-item" v-for="(tmp,i) in hotSearchList" :key="i"><a href="/">{{tmp.Word}}</a></span>
            </p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import TemplateClass from "@/components/home/TemplateClass.vue";
export default {
  data() {
    return {
      keywords: "",
      hotSearchList: [],
      show: false
    };
  },
  props: ["isFixed", "barList"],
  methods: {
    handleSearch(keywords) {
      console.log(13);
      let n, id, subtitle, title;
      n = this.$route.query.n || "";
      id = this.$route.query.id || "";
      this.$router.push({
        path: "/templateList/templateCenter",
        query: { k: keywords, n: n, id: id }
      });
    },
    /** 显示热门搜索框,关键词 */
    isShowSearchBox(type) {
      setTimeout(() => {
        this.show = type
      }, 100)
    }
  },
  computed: {
    path() {
      return this.$route.path;
    }
  },
  components: {
    TemplateClass
  }
};
</script>

<style lang="less" scoped>
#header {
  background: rgba(255, 255, 255, 1);
  box-shadow: 0px 0px 44px 20px rgba(203, 211, 217, 0.4);
}
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 1200px;
  height: 70px;
  margin: 0 auto;
  .header-left {
    display: flex;
    align-items: center;
    .logo {
      width: 176px;
      height: 55px;
      object-fit: contain;
      margin-right: 79px;
      cursor: pointer;
    }
    ul {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 38px;
      margin-left: 15px;
      &>a {
        margin-right: 20px;
      }
      .menu-list {
        display: inline-block;
        width: 110px;
        height: 38px;
        line-height: 38px;
        text-align: center;
        border-radius: 19px;
        color: rgba(51, 51, 51, 1);
        font-size: 16px;
        cursor: pointer;
        transition: all 0.25s;
        &:hover {
          background: #e1e3e8;
          border-color: #e1e3e8;
        }
      }
    }
    .bar-menu-wrap {
      position: relative;
      width: 255px;
      &:hover .bar-menu-list{
          display: block;
      }
      .bar-menu-list {
        position: absolute;
        top: 44px;
        left: 0;
        display: none;
        padding-top: 12px;
        animation: move-out .3s;
      }
    }
    .bar-menu {
      display: inline-block;
      width: 100%;
      height: 45px;
      line-height: 45px;
      font-size: 16px;
      color: rgba(255, 255, 255, 1);
      padding: 0 16px;
      border-radius: 5px;
      cursor: pointer;
      .bar-img {
        width: 21px;
        height: 21px;
        display: inline-block;
        vertical-align: middle;
        margin-right: 15px;
      }
    }
  }
  .header-right {
    .search-input {
      position: relative;
      .input-select {
        width: 375px;
        height: 42px;
        position: relative;
        input {
          border: 2px solid transparent;
          border-radius: 22px 0 0 22px;
          height: 42px;
          width: 100%;
          outline: none;
          padding-left: 20px;
        }
        .search-btn {
          display: inline-block;
          width: 96px;
          height: 42px;
          line-height: 42px;
          border-radius: 0 22px 22px 0;
          position: absolute;
          top: 0;
          right: -18px;
          font-size: 16px;
          text-align: center;
          font-family: MicrosoftYaHei;
          font-weight: 400;
          color: rgba(255, 255, 255, 1);
          cursor: pointer;
        }
      }
      .hot-search {
        position: absolute;
        top: 42px;
        left: 18px;
        background: #fff;
        right: 91px;
        -webkit-box-shadow: 0 18px 20px 0 rgba(20, 33, 65, 0.14);
        box-shadow: 0 18px 20px 0 rgba(20, 33, 65, 0.14);
        border-radius: 0 0 6px 6px;
        min-width: 160px;
        p {
          height: 36px;
          line-height: 36px;
          padding: 0 20px;
          span:first-child {
            color: rgba(205, 205, 205, 1);
          }
        }
        .search-item {
          margin: 0 10px;
          cursor: pointer;
          color: rgba(51, 51, 51, 1);
          &:hover {
            color: @color;
          }
        }
      }
    }
  }
}
</style>
